package com.thread.base01_thread;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class App4 {
    public static void main(String[] args) {
        ThreadPoolExecutor executor =
                new ThreadPoolExecutor(
                        20,
                        20,
                        100,
                        TimeUnit.SECONDS,
                        new ArrayBlockingQueue<>(10),
                        new ThreadPoolExecutor.AbortPolicy());

        // 通过线程数创建10个线程
        for (int i = 0; i < 10; i++) {
            executor.submit(() -> {
                System.out.println("线程" + Thread.currentThread().getName() + "执行");
                try {
                    Thread.sleep(90000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }

            });
        }

        // 关闭线程池，会等待所有线程执行完毕
        executor.shutdown();
        while (!executor.isTerminated()) {// 判断线程池是否终止
        }
        System.out.println("所有线程执行完毕");

    }
}
